package net.dl.ss.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.dl.ss.service.ContextManager;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author yakovlev.yuriy@gmail.com
 * @since 12.8.2008
 */
@Controller
public class ContextController extends BaseController {
	
	@RequestMapping("/updateContext.htm")
	public void contextHandler(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ContextManager.setCurrentEvent(request);
		ContextManager.setCurrentCategory(request);
	}

	@RequestMapping("/getCurrentEvent.htm")
	public void getCurrentEventHandler(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ServletOutputStream  os = response.getOutputStream();
		modifyResponseHeader(response, "text/plain");
		Long event = ContextManager.getCurrentEvent(request);
		os.print("{event:"+event+"}");
	    os.close();
	}

}
